import request from '@/utils/request'
import {
  DeleteProductResponse,
  PageInfo,
  ProductFormData,
  ProductResponse,
  ProductResponseData,
} from './type'

export const getProduct = (pageInfo: PageInfo) => {
  return request.get<any, ProductResponseData>('/product/page', {
    params: pageInfo,
  })
}

export const addProduct = (product: ProductFormData) => {
  if (product._id) {
    return request.put<any, ProductResponse>('/product/update', product)
  }
  return request.post<any, ProductResponse>('/product/add', product)
}

export const deleteProduct = (id: string) => {
  return request.delete<any, DeleteProductResponse>('/product/delete', {
    params: {
      id,
    },
  })
}
